﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace The_Last_Knights.GUI
{
    public class NormalButton: Button
    {
        #region Attributes
        protected bool _isClick;
        #endregion

        #region Properties
        public bool IsClick
        {
            get { return _isClick; }
            set { _isClick = value; }
        }
#endregion

        public NormalButton(Game game, Text text, string normal, string hover, string push, 
            string ID, Vector2 pos, Vector2 size, Texture2D background) 
            : base(game, text, normal, hover, push, ID, pos, size, background)
        {
            _isClick = false;
        }

        
        public override void Update(GameTime gameTime)
        {            
            MouseState ms = Mouse.GetState();
            Point p = new Point(ms.X, ms.Y);
            Rectangle boundary = new Rectangle((int)_position.X, (int)_position.Y, (int)_size.X, (int)_size.Y);
            if (boundary.Contains(p))
            {
                if (ms.LeftButton == ButtonState.Pressed)
                {
                    ChangePushState();
                    _isClick = true;
                }
                if (ms.LeftButton == ButtonState.Released)
                    if (_isClick)
                    {
                        ChangeNormalState();
                        _isClick = false;
                        OnEvent(this, "EVENT_GUI_BUTTON_CLICK", null, null);
                    }
                    else
                    {
                        ChangeHoverState();
                        OnEvent(this, "EVENT_GUI_BUTTON_HOVER", null, null);
                    }
            }
            else
            {
                _isClick = false;
                ChangeNormalState();                
            }            
        }        
    }
}
